// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var router = require("../hash/pageRouter");
	var nature = $("#nature").val();
	var enterpriseId;
	var validate = require("validate");
	var tools = require("tools");
	var databind = require("databind");
	var modifyClienManage_details = require("./clienManage_details.css");
	var authenticationId;
	var init = function(page) {
		authenticationId = page.params.authenticationId;
		$(".nav_active").removeClass("nav_active1");
		$(".authenticationState").addClass("nav_active1");
		inquireEnterpriseDetail(enterpriseId);
		router.init();
		initEvent();
	};

	var initEvent = function() {
		$("#modifyClienManage_details").on("change", "#creditCard", function() {
			var bn = tools.getBankName($(this).val());
			if (bn == "") {
				alert("未知开户行！");
			} else {
				$("#depositBank").val(bn);
			}
		});

		$("#modifyClienManage_details").on(
				"change",
				"#legalIdcard",
				function() {
					var promptString = validate.isIdCard($(this),
							"请输入正确的身份证号码!");
					if ("" != promptString) {
						base.alert(2, promptString)
					}
				});

		layer.tips(tools.formatCurrency($("input[name=registeredCapital]")
				.val())
				+ '('
				+ tools.changeMoneyToChinese($("input[name=registeredCapital]")
						.val()) + ')', 'input[name=registeredCapital]', {
			tips : [ 1, '#3595CC' ],
			time : 3000
		});

		$("#modifyClienManage_details").on(
				"focus",
				"input[name=registeredCapital]",
				function() {
					var $this = $(this);
					layer.tips(tools.formatCurrency($this.val())
							+ '('
							+ tools.changeMoneyToChinese($(
									"input[name=registeredCapital]").val())
							+ ')', 'input[name=registeredCapital]', {
						tips : [ 1, '#3595CC' ],
						time : 3000
					});
				});

		$("#modifyClienManage_details").on(
				"change",
				"input[name=registeredCapital]",
				function() {
					var $this = $(this);
					layer.tips(tools.formatCurrency($this.val())
							+ '('
							+ tools.changeMoneyToChinese($(
									"input[name=registeredCapital]").val())
							+ ')', 'input[name=registeredCapital]', {
						tips : [ 1, '#3595CC' ],
						time : 3000
					});
				});

		//返回
		$(".next").on("click", function() {
			router.route("account/accountRecordModify.html");
		});

		// 单位类型 nature
		// 企业名 enterpriseName
		// 单位注册号 businessLicence
		// 营业执照所在地 address
		// 联系地址 contactAddress
		// 经营范围 businessScope
		// 注册资金 registeredCapital
		// 营业期限 businessTimeLimit
		// 法定代表人姓名 legalPerson
		// 身份证号 legalIdcard
		// 证件有效期 legalPeriod
		// 开户行 depositBank
		// 开户名称 accountHolder
		// 银行卡号 creditCard
	};

	// 查询企业详细信息
	var inquireEnterpriseDetail = function() {
		base.fnAjax({
					action : "queryEnterpriseModify.json",// queryEnterpriseModify
					oData : {
						authenticationId : authenticationId
					}, // 传递参数
					fnSuccess : function(data) {
						if (data.status == 200) {
							databind.fillForm($("#clienManage_details"),
									data.datas[0]);
							$("select[name=province]").html(
									"<option>" + data.datas[0].province
											+ "</option>");
							$("select[name=city]").html(
									"<option>" + data.datas[0].city
											+ "</option>");
							$("select[name=district]").html(
									"<option>" + data.datas[0].district
											+ "</option>");
						} else {
							base.alert(2, data.message);
						}
						// 判断认证状态
						if (data.datas[0].authentication != undefined
								&& data.datas[0].authentication != 3) { // 未认证
							$(".return").hide();
						}
						if (data.datas[0].authentication != undefined
								&& data.datas[0].authentication == 3) { // 已认证
							$(".next").hide();
						}
					}
				});
		databind.disableInput ("#clienManage_details");
		databind.enableInput("#financeEvidentiary");
	};

	// 连接e签宝生成证书,返回账户唯一标识
	var addOrganize = function() {
		base.fnAjax({
			action : "addOrganize.json",
			async : false,
			oData : {}, // 传递参数
			fnSuccess : function(data) {
			}
		});
	};

	return {
		init : init
	};
});